//package com.wang.springbootinit.aop;
//
//import cn.hutool.core.util.ObjectUtil;
//import com.wang.springbootinit.model.entity.User;
//import com.wang.springbootinit.service.UserService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
///**
// * 拦截器，对未登录的用户进行拦截
// */
//@Slf4j
//@Component
//public class LoginInterceptor implements HandlerInterceptor {
//
//    @Resource
//    private UserService userService;
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        User loginUser = userService.getLoginUser(request);
//        if (ObjectUtil.isNull(loginUser)) {
//            log.info("LoginInterceptor preHandle 当前请求用户未登录");
//            return false;
//        }
//        ContextUtil.setUser(loginUser);
//        return true;
//    }
//
//    @Override
//    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
//        HandlerInterceptor.super.postHandle(request, response, handler, modelAndView);
//    }
//
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//        HandlerInterceptor.super.afterCompletion(request, response, handler, ex);
//        ContextUtil.remove();
//    }
//}
